﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Model;
using System.Data.SqlClient;
using System.Globalization;
using Model.EntityModel;

namespace DataAccess
{
    public static class DirectActionDataAccess
    {
        
        public static DirectAction InsertDirectAction(DirectAction dischargeBallot)
        {
            try
            {
                BrigadaEntities context = new BrigadaEntities();
                context.AddToDirectAction(dischargeBallot);
                context.SaveChanges();
                return dischargeBallot;
            }
            catch
            {
                return null;
            }
        }

        public static DirectAction UpdateDirectAction(long idComplaint, DirectAction newInfo)
        {
            BrigadaEntities context = new BrigadaEntities();
            var complaint = (from c in context.DirectAction
                             where c.Id == idComplaint
                             select c).SingleOrDefault();
            complaint.Id = newInfo.Id;
            complaint.IncidentNature = newInfo.IncidentNature;
            complaint.IncidentReport = newInfo.IncidentReport;
            complaint.IncidentTime = newInfo.IncidentTime;
            complaint.RegistrationDate = newInfo.RegistrationDate;
            complaint.CIEmployee = newInfo.CIEmployee;
            complaint.CIInterveningPolice = newInfo.CIInterveningPolice;
            complaint.Status = newInfo.Status;
            context.SaveChanges();
            return complaint;
        }

        public static DirectAction GetDirectActionById(long idDirectAction)
        {
            BrigadaEntities context = new BrigadaEntities();
            var complaint = (from c in context.DirectAction
                             where c.Id == idDirectAction
                             select c).Single();
            return complaint;
        }
    }       
}
